package com.zy.design.dd;
import	java.util.ArrayList;
import	java.util.List;

import com.zy.design.dd.abs.CountHandler;
import com.zy.design.dd.abs.Counter;
import com.zy.design.dd.abs.EmptyCountHandler;
import com.zy.design.dd.abs.MeetCounterHandler;
import com.zy.design.dd.entity.CountData;
import com.zy.design.dd.entity.DataLine;
import lombok.NoArgsConstructor;
import lombok.extern.flogger.Flogger;
import lombok.extern.slf4j.Slf4j;

/**
 * @author zhaoyi
 * @date 2021/3/19 13:05
 */
public class AppContext {

    private Counter counter;

    // 饿汉式单例
    private static final AppContext instance = new AppContext();

    private void initializeBeans() {
        //初始化加载
        counter = new Counter();
        //计算空驶时长
        System.out.println("加载 计算空驶时长!!!!!!");
        counter.addHandler(new EmptyCountHandler());

        System.out.println("加载 计算节课时长!!!!!!");
        counter.addHandler(new MeetCounterHandler());

        System.out.println("加载很多其他自定义的...省略了");
        System.out.println("----------初始化完成------------");
    }

    private AppContext() {
        initializeBeans();
    }

    public static AppContext getInstance(){
        return instance;
    }

    public CountData run(DataLine dataLine){
        CountData countData = new CountData(dataLine);
        return counter.count(dataLine,countData);
    }






}
